package com.hjm.project.terminal.section.service.impl;

import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.project.agentInfo.profitSbOrder.utils.PublicTypeUtils;
import com.hjm.project.job.task.service.IJobTaskService;
import com.hjm.project.terminal.section.domain.TemplateData1;
import com.hjm.project.terminal.section.mapper.TerminalSectionMapper;
import com.hjm.project.terminal.section.service.ITerminalSectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author puyiliang
 * @date create in 2020/12/4 15:28
 */
@Service
public class TerminalSectionServiceImpl implements ITerminalSectionService {

    @Autowired
    private TerminalSectionMapper terminalSectionMapper;
    @Autowired
    private IJobTaskService jobTaskService;

    @Override
    public List<Map<String, String>> selectTerminalSectionList(Map<String, String> params) {
        return terminalSectionMapper.selectTerminalSectionList(params);
    }

    @Override
    public List<Map<String, String>> selectTerminalStatisticsList(Map<String, String> params) {
        return terminalSectionMapper.selectTerminalStatisticsList(params);
    }

    @Override
    public List<Map<String, String>> selectTerminalThreeSectionList(Map<String, String> params) {
        return terminalSectionMapper.selectTerminalThreeSectionList(params);
    }

    @Override
    public List<Map<String, String>> selectTerminalThreeStatisticsList(Map<String, String> params) {
        return terminalSectionMapper.selectTerminalThreeStatisticsList(params);
    }

    @Override
    public List<Map<String, Object>> selectTerminalSection(Map<String, String> params) {
        return terminalSectionMapper.selectTerminalSection(params);
    }
    @Override
    public Map selectTerminalSectionSum(Map<String, String> params) {
        return terminalSectionMapper.selectTerminalSectionSum(params);
    }

    @Override
    @Async
    public Integer export(Map<String, String> params, String addMan) {
        List<Map<String, Object>> list = terminalSectionMapper.selectTerminalSection(params);
        List<TemplateData1> templatesDataList = new ArrayList<>();
        for (Map<String, Object> data : list) {
            TemplateData1 templateData = new TemplateData1();
            templateData.setPOSNO(data.get("POSNO") == null ? "" : data.get("POSNO").toString());
            templateData.setSN(data.get("SN") == null ? "" : data.get("SN").toString());
            templateData.setACT_ID(data.get("ACT_ID") == null ? "" : data.get("ACT_ID").toString());
            templateData.setACT_NAME(data.get("ACT_NAME") == null ? "" : data.get("ACT_NAME").toString());
            templateData.setCREATEDATE(data.get("CREATEDATE") == null ? "" : data.get("CREATEDATE").toString());
            templateData.setACHIEVEMENT_DATE(data.get("ACHIEVEMENT_DATE") == null ? "" : data.get("ACHIEVEMENT_DATE").toString());
            templateData.setACHIEVEMENT_STAGE(PublicTypeUtils.getStageType(data.get("ACHIEVEMENT_STAGE")));
            templateData.setRETURN_MONEY(data.get("RETURN_MONEY") == null ? "" : data.get("RETURN_MONEY").toString());
            templateData.setRETURN_DATE(data.get("RETURN_DATE") == null ? "" : data.get("RETURN_DATE").toString());
            templateData.setTYPE(PublicTypeUtils.getSnReturnType(data.get("TYPE")));
            templateData.setPOS_TYPE(PublicTypeUtils.getPosType(data.get("POS_TYPE")));
            templateData.setMERNO(data.get("MERNO") == null ? "" : data.get("MERNO").toString());
            templateData.setSCREEN_NAME(data.get("SCREEN_NAME") == null ? "" : data.get("SCREEN_NAME").toString());
            templateData.setDIRECTLY_UNDER_AGENTNO(data.get("DIRECTLY_UNDER_AGENTNO") == null ? "" : data.get("DIRECTLY_UNDER_AGENTNO").toString());
            templateData.setAGENT_NAME(data.get("AGENT_NAME") == null ? "" : data.get("AGENT_NAME").toString());
            templateData.setRETURN_AGENTID(data.get("RETURN_AGENTID") == null ? "" : data.get("RETURN_AGENTID").toString());
            templateData.setRETURN_AGENTNAME(data.get("RETURN_AGENTNAME") == null ? "" : data.get("RETURN_AGENTNAME").toString());
            templatesDataList.add(templateData);
        }
        ExcelUtil<TemplateData1> util = new ExcelUtil<TemplateData1>(TemplateData1.class);
        jobTaskService.asyncDownLoad("终端达标明细",Long.parseLong("10"),"终端达标明细",addMan,templatesDataList,util);
        return list.size();
    }

    @Override
    public List<Map<String, Object>> selectTerminalStatistics(Map<String, String> params) {
        return terminalSectionMapper.selectTerminalStatistics(params);
    }
}
